home *** CD-ROM | disk | FTP | other *** search
/ Eagles Nest BBS 8 / Eagles_Nest_Mac_Collection_Disc_8.TOAST / Developer Tools⁄Additions / TextPertDK#1 / MPW C Sources & Examples.image / Example1 / AppleScan.c next >
Text File  |  1992-01-02  |  11KB  |  411 lines

  1. /*
  2.         This file implements the calls that are defined in the
  3.         APPLE SCANNER TECHNICAL REFERENCE MANUAL.
  4.         
  5.         Ported from Pascal to C by CTA, Inc., 1991.
  6.         
  7. */
  8.  
  9. #include <devices.h>
  10. #include <string.h>
  11.  
  12. #include "AppleScan.h"
  13.  
  14.         /* Opening and closing the driver */
  15.  
  16.         /* ScOpen        OpenDriver   */
  17.         /* ScClose    Closedriver */
  18.  
  19.         /* Getting Standard Features */
  20.  
  21. #define    ScGetStdFeaturesStCall        2
  22. #define    ScGetResStCall                        3
  23. #define    ScGetHalfTonesStCall            4
  24.  
  25.         /* Setting Scan Area */
  26.  
  27. #define    ScSetScanAreaCtlCall            2
  28.  
  29.         /* Reading Scanned Data */
  30.  
  31.         /* ScDoScan        ReadCall */
  32. #define    ScAbortScanCtlCall                1
  33.  
  34.         /* Getting Advanced Features calls' code */
  35.     
  36. #define    ScGetAdvFeaturesStCall        5
  37. #define    ScSetHtPatternCtlCall            4
  38.  
  39. #define    ScSetGroup3CtlCall                5
  40. #define    ScSetNoHomeCtlCall                6
  41. #define    ScSetLampCtlCall                    7
  42. #define    ScSetGrayMapCtlCall                8
  43. #define    ScSetThresHoldCtlCall            9
  44. #define    ScSetWaitButtonCtlCall        10
  45.  
  46. /***************************************************************************************/
  47. /******************************* ROUTINE IMPLEMENTATION ********************************/
  48. /***************************************************************************************/
  49.     /* Opening and Closing the standard driver */
  50. /***************************************************************************************/
  51. pascal OSErr ScOpen(Str255 Nombre, short *RefNum)   /* Variation ; Also receives the name */
  52.     /* Opens the driver and reset the scanner to it default values. */
  53.  
  54. {
  55. return OpenDriver(Nombre, RefNum);
  56. }
  57.     
  58. /***************************************************************************************/
  59. pascal OSErr ScClose(short RefNum)
  60.     /* Closes the driver and releases the scanner. */
  61. {
  62. return CloseDriver(RefNum);
  63. }
  64.     
  65.     
  66.     /* Getting Standard Features */
  67. /***************************************************************************************/
  68. pascal OSErr ScGetStdFeatures(short RefNum,
  69.                                                             ScStdFeaturesPtr    stdFeaturesPtr,
  70.                                                             short    Length)
  71.     /* Gives the user a complete description of the features of the scanner, following the 
  72.       structure described in the stdFeaturesRec returned. */
  73. {
  74. char                        NullStr[10];
  75. ParamBlockRec        ParamBl;
  76.  
  77. ParamBl.cntrlParam.ioCompletion = nil;
  78. ParamBl.cntrlParam.ioCRefNum = RefNum;
  79. strcpy(NullStr, "");
  80. ParamBl.cntrlParam.ioNamePtr = (StringPtr)NullStr;
  81.  
  82. ParamBl.cntrlParam.csCode = ScGetStdFeaturesStCall;
  83. ((long *)ParamBl.cntrlParam.csParam)[0] = (long)stdFeaturesPtr;
  84. /* will take position 0 and 1 of the short array */
  85. ParamBl.cntrlParam.csParam[2] = Length;
  86.  
  87. return (PBStatus(&ParamBl, false));
  88.  
  89. }
  90.  
  91.  
  92. /***************************************************************************************/
  93. pascal OSErr ScGetRes(short RefNum,
  94.                                             short            CompType,
  95.                                             ScResPtr    ResPtr)
  96.     
  97.     /* Returns an array with the resolutions supported by the scanner.
  98.       The number of Resolutions supported by the scanner is defined in the stdFeaturesRec.  */
  99. {
  100. char                        NullStr[10];
  101. ParamBlockRec        ParamBl;
  102.  
  103. ParamBl.cntrlParam.ioCompletion = nil;
  104. ParamBl.cntrlParam.ioCRefNum = RefNum;
  105. strcpy(NullStr, "");
  106. ParamBl.cntrlParam.ioNamePtr = (StringPtr)NullStr;
  107.  
  108. ParamBl.cntrlParam.csCode = ScGetResStCall;
  109. ParamBl.cntrlParam.csParam[0] = CompType;
  110. ((long *)ParamBl.cntrlParam.csParam)[1] = (long)ResPtr;
  111. /* will take position 1 and 2 of the short array */
  112.  
  113. return (PBStatus(&ParamBl, false));
  114.  
  115. }
  116.  
  117.  
  118. /***************************************************************************************/
  119. pascal OSErr ScGetHalfTones(short RefNum,
  120.                                                 short            CompType,
  121.                                                 ScHalfTonePtr    HalfTonePtr)
  122.  
  123.     /* Returns the list of supported halftone patterns.
  124.       This list has the structure described in the schalftone array. */
  125. {
  126. char                        NullStr[10];
  127. ParamBlockRec        ParamBl;
  128.  
  129. ParamBl.cntrlParam.ioCompletion = nil;
  130. ParamBl.cntrlParam.ioCRefNum = RefNum;
  131. strcpy(NullStr, "");
  132. ParamBl.cntrlParam.ioNamePtr = (StringPtr)NullStr;
  133.  
  134. ParamBl.cntrlParam.csCode = ScGetHalfTonesStCall;
  135. ParamBl.cntrlParam.csParam[0] = CompType;
  136. ((long *)ParamBl.cntrlParam.csParam)[1] = (long)HalfTonePtr;
  137. /* will take position 1 and 2 of the short array */
  138.  
  139. return (PBStatus(&ParamBl, false));
  140.  
  141. }
  142.       
  143.       
  144.  
  145.     /* Setting Scan Area */
  146. /***************************************************************************************/
  147. pascal OSErr ScSetScanArea(short RefNum,
  148.                                                    ScScanAreaPtr ScanAreaPtr)
  149.     
  150.     /* Sets the area to scan, and also the parameters to use in the scan of that area. */
  151. {
  152. char                        NullStr[10];
  153. ParamBlockRec        ParamBl;
  154.  
  155. ParamBl.cntrlParam.ioCompletion = nil;
  156. ParamBl.cntrlParam.ioCRefNum = RefNum;
  157. strcpy(NullStr, "");
  158. ParamBl.cntrlParam.ioNamePtr = (StringPtr)NullStr;
  159.  
  160. ParamBl.cntrlParam.csCode = ScSetScanAreaCtlCall;
  161. ((long *)ParamBl.cntrlParam.csParam)[0] = (long)ScanAreaPtr;
  162. /* will take position 1 and 2 of the short array */
  163.  
  164. return (PBControl(&ParamBl, false));
  165.  
  166. }
  167.     
  168.     
  169.  
  170.     /* Reading Scanned Data */
  171. /***************************************************************************************/
  172. pascal OSErr ScDoScan(short RefNum,
  173.                                           Ptr        Buffer,
  174.                                           long    *Count,
  175.                                           short    Unused,
  176.                                           short    ByteWidth,
  177.                                           short    RowBytes)
  178.     
  179.     /* Starts scan and returns data following the parameters previously set. */
  180. {
  181. char                        NullStr[10];
  182. ParamBlockRec        ParamBl;
  183. short                        Error;
  184.  
  185. ParamBl.cntrlParam.ioCompletion = nil;
  186. ParamBl.cntrlParam.ioCRefNum = RefNum;
  187. strcpy(NullStr, "");
  188. ParamBl.cntrlParam.ioNamePtr = (StringPtr)NullStr;
  189.  
  190. ParamBl.ioParam.ioReqCount = *Count;
  191. ParamBl.ioParam.ioBuffer = Buffer;
  192. ParamBl.ioParam.ioPosMode = Unused;
  193. ParamBl.ioParam.ioPosOffset = ((long)ByteWidth << 16) | (long)RowBytes;
  194.  
  195. Error = PBRead(&ParamBl, false);
  196.  
  197. *Count = ParamBl.ioParam.ioActCount;
  198.  
  199. return (Error);
  200.  
  201. }
  202.     
  203.     
  204. /***************************************************************************************/
  205. pascal OSErr ScAbortScan(short RefNum)
  206.  
  207.     /* Aborts the scan in progress. Is the only call that the scanner
  208.       will answer to while a scan is being done.        */
  209. {
  210. char                        NullStr[10];
  211. ParamBlockRec        ParamBl;
  212.  
  213. ParamBl.cntrlParam.ioCompletion = nil;
  214. ParamBl.cntrlParam.ioCRefNum = RefNum;
  215. strcpy(NullStr, "");
  216. ParamBl.cntrlParam.ioNamePtr = (StringPtr)NullStr;
  217.  
  218. ParamBl.cntrlParam.csCode = ScAbortScanCtlCall;
  219.  
  220. return (PBControl(&ParamBl, false));
  221.  
  222. }
  223.  
  224.  
  225.  
  226.     /* Getting Advanced Features */
  227. /***************************************************************************************/
  228. pascal OSErr ScGetAdvFeatures(short RefNum,
  229.                           ScAdvFeaturesPtr    AdvFeaturesPtr,
  230.                           short                            Length)
  231.     
  232.     /* Gives the user avdanced features of the scanner. Returns a
  233.       handle to ScAdvFeaturesRec. If a scanner doesn't support this call,
  234.       a statuserr value of -18 is returned. */
  235. {
  236. char                        NullStr[10];
  237. ParamBlockRec        ParamBl;
  238.  
  239. ParamBl.cntrlParam.ioCompletion = nil;
  240. ParamBl.cntrlParam.ioCRefNum = RefNum;
  241. strcpy(NullStr, "");
  242. ParamBl.cntrlParam.ioNamePtr = (StringPtr)NullStr;
  243.  
  244. ParamBl.cntrlParam.csCode = ScGetAdvFeaturesStCall;
  245. ((long *)ParamBl.cntrlParam.csParam)[0] = (long)AdvFeaturesPtr;
  246. /* will take position 0 and 1 of the short array */
  247. ParamBl.cntrlParam.csParam[2] = Length;
  248.  
  249. return (PBStatus(&ParamBl, false));
  250.  
  251. }
  252.       
  253.       
  254. /***************************************************************************************/
  255. pascal OSErr ScSetHtPattern(short            RefNum,
  256.                                                         ScPatPtr    PatPtr)
  257.  
  258.     /* Sets the downloadable halftone pattern */
  259. {
  260. char                        NullStr[10];
  261. ParamBlockRec        ParamBl;
  262.  
  263. ParamBl.cntrlParam.ioCompletion = nil;
  264. ParamBl.cntrlParam.ioCRefNum = RefNum;
  265. strcpy(NullStr, "");
  266. ParamBl.cntrlParam.ioNamePtr = (StringPtr)NullStr;
  267.  
  268. ParamBl.cntrlParam.csCode = ScSetHtPatternCtlCall;
  269. ((long *)ParamBl.cntrlParam.csParam)[0] = (long)PatPtr;
  270. /* will take position 1 and 2 of the short array */
  271.  
  272. return (PBControl(&ParamBl, false));
  273.  
  274. }
  275.     
  276.     
  277. /***************************************************************************************/
  278. pascal OSErr ScSetGroup3(short RefNum,
  279.                                                  Boolean    CompressOn)
  280.  
  281.     /* Enables and disables data compression in data returned by the scanner.
  282.       The compression used is Group III, 1-dimensional standard FAX encoding. */
  283. {
  284. char                        NullStr[10];
  285. ParamBlockRec        ParamBl;
  286.  
  287. ParamBl.cntrlParam.ioCompletion = nil;
  288. ParamBl.cntrlParam.ioCRefNum = RefNum;
  289. strcpy(NullStr, "");
  290. ParamBl.cntrlParam.ioNamePtr = (StringPtr)NullStr;
  291.  
  292. ParamBl.cntrlParam.csCode = ScSetGroup3CtlCall;
  293. ParamBl.cntrlParam.csParam[0] = ((CompressOn) ? (1) : (0));
  294.  
  295. return (PBControl(&ParamBl, false));
  296.  
  297. }
  298.       
  299.       
  300. /***************************************************************************************/
  301. pascal OSErr ScSetNoHome(short RefNum,
  302.                                                  Boolean    NoHome)
  303.  
  304.     /* This function control whether or not the carriage assembly returns
  305.       to the home position after scanning. */
  306. {
  307. char                        NullStr[10];
  308. ParamBlockRec        ParamBl;
  309.  
  310. ParamBl.cntrlParam.ioCompletion = nil;
  311. ParamBl.cntrlParam.ioCRefNum = RefNum;
  312. strcpy(NullStr, "");
  313. ParamBl.cntrlParam.ioNamePtr = (StringPtr)NullStr;
  314.  
  315. ParamBl.cntrlParam.csCode = ScSetNoHomeCtlCall;
  316. ParamBl.cntrlParam.csParam[0] = ((NoHome) ? (1) : (0));
  317.  
  318. return (PBControl(&ParamBl, false));
  319.  
  320. }
  321.       
  322.       
  323. /***************************************************************************************/
  324. pascal OSErr ScSetLamp(short RefNum,
  325.                                            Boolean    LampOn)
  326.  
  327.     /* This call turns the fluorescent lamp On and Off. */
  328. {
  329. char                        NullStr[10];
  330. ParamBlockRec        ParamBl;
  331.  
  332. ParamBl.cntrlParam.ioCompletion = nil;
  333. ParamBl.cntrlParam.ioCRefNum = RefNum;
  334. strcpy(NullStr, "");
  335. ParamBl.cntrlParam.ioNamePtr = (StringPtr)NullStr;
  336.  
  337. ParamBl.cntrlParam.csCode = ScSetLampCtlCall;
  338. ParamBl.cntrlParam.csParam[0] = ((LampOn) ? (1) : (0));
  339.  
  340. return (PBControl(&ParamBl, false));
  341.  
  342. }
  343.     
  344.     
  345. /***************************************************************************************/
  346. pascal OSErr ScSetGrayMap(short RefNum,
  347.                                               short    GrayMap)
  348.  
  349.     /* Sets the gray map curve used while scanning. */
  350. {
  351. char                        NullStr[10];
  352. ParamBlockRec        ParamBl;
  353.  
  354. ParamBl.cntrlParam.ioCompletion = nil;
  355. ParamBl.cntrlParam.ioCRefNum = RefNum;
  356. strcpy(NullStr, "");
  357. ParamBl.cntrlParam.ioNamePtr = (StringPtr)NullStr;
  358.  
  359. ParamBl.cntrlParam.csCode = ScSetGrayMapCtlCall;
  360. ParamBl.cntrlParam.csParam[0] = GrayMap;
  361.  
  362. return (PBControl(&ParamBl, false));
  363.  
  364. }
  365.     
  366.     
  367. /***************************************************************************************/
  368. pascal OSErr ScSetThresHold(short RefNum,
  369.                                                         short    Threshold)
  370.  
  371.     /* Sets the AutoBackground threshold level. */
  372. {
  373. char                        NullStr[10];
  374. ParamBlockRec        ParamBl;
  375.  
  376. ParamBl.cntrlParam.ioCompletion = nil;
  377. ParamBl.cntrlParam.ioCRefNum = RefNum;
  378. strcpy(NullStr, "");
  379. ParamBl.cntrlParam.ioNamePtr = (StringPtr)NullStr;
  380.  
  381. ParamBl.cntrlParam.csCode = ScSetThresHoldCtlCall;
  382. ParamBl.cntrlParam.csParam[0] = Threshold;
  383.  
  384. return (PBControl(&ParamBl, false));
  385.  
  386. }
  387.     
  388.     
  389. /***************************************************************************************/
  390. pascal OSErr ScSetWaitButton(short RefNum,
  391.                                                          Boolean    WaitButton)
  392.  
  393.     /* This function controls if the scan will begin after a
  394.       DoScan command is send or if the scanner will wait for the
  395.       button it has to be pressed before beginning to scan. */        
  396. {
  397. char                        NullStr[10];
  398. ParamBlockRec        ParamBl;
  399.  
  400. ParamBl.cntrlParam.ioCompletion = nil;
  401. ParamBl.cntrlParam.ioCRefNum = RefNum;
  402. strcpy(NullStr, "");
  403. ParamBl.cntrlParam.ioNamePtr = (StringPtr)NullStr;
  404.  
  405. ParamBl.cntrlParam.csCode = ScSetWaitButtonCtlCall;
  406. ParamBl.cntrlParam.csParam[0] = ((WaitButton) ? (1) : (0));
  407.  
  408. return (PBControl(&ParamBl, false));
  409.  
  410. }
  411.